Passed
Pull Request — master (#75)
by Mathieu
01:46
created

IsMaximumTimeSpentReached   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 13
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A isSatisfiedBy 0 8 1
1
import {Inject} from '@nestjs/common';
2
import {ISpecification} from 'src/Domain/ISpecification';
3
import {IEventRepository} from '../Repository/IEventRepository';
4
import {Event} from '../Event.entity';
5
6
export class IsMaximumTimeSpentReached implements ISpecification {
7
  constructor(
8
    @Inject('IEventRepository')
9
    private readonly eventRepository: IEventRepository
10
  ) {}
11
12
  public async isSatisfiedBy(event: Event): Promise<boolean> {
13
    const timeSpent = await this.eventRepository.getDayTimeSpentByUser(
14
      event.getUser(),
15
      event.getDate()
16
    );
17
18
    return timeSpent + event.getTime() > Event.MAXIMUM_TIMESPENT_PER_DAY;
19
  }
20
}
21